An intuitive but inefficient search algorithm.
Traverse through the array to search for an element. If found, return it. Otherwise, signal not found.
(DEV285x)
Code
* static void linearSearch(int[] [1](/view/1)st, int x) {
* * int n = [1](/view/1)st.length;
* * for (int i = 0; i < n; i++) {
* * * if ([1](/view/1)st[i] == v) {
* * * * System.[o](/view/O)ut.println("found @ " + i);
* * * * return;
* * * }
* * }
* * System.[o](/view/O)ut.println("the [element](/view/Element) is not in the array");
* * return;
* }
(DEV285x)